#include "comm.hpp"

int main()
{
    key_t key = GetKey();
    // std::cout << "key: " << ToHex(key) << std::endl;

    // std::cout << "获取共享内存" << std::endl;
    int shmid = Getshm(key);
    // std::cout << shmid << std::endl;

    // std::cout << "挂接" << std::endl;
    char *s = (char*)shmat(shmid, nullptr, 0);

    int fd = open(filename.c_str(), O_WRONLY);
    // TODO
    char ch = 'a';
    for (; ch <= 'z'; ch++)
    {
        s[ch-'a'] = ch;
        std::cout << "客户端写入：" << ch << std::endl; 
        sleep(1);

        // 通知server端，client端已经写入了
        int code = 1;
        write(fd, &code, sizeof(int));
    }

    // std::cout << "去关联" << std::endl;
    shmdt(s);

    close(fd);
    return 0;
}
